/*
 * @lc app=leetcode.cn id=7 lang=javascript
 *
 * [7] 整数反转
 */

// @lc code=start
/**
 * @param {number} x
 * @return {number}
 */
var reverse = function (x) {
  const isNegative = x < 0;
  const max = Math.pow(2, 31) - 1;

  x = Math.abs(x);

  const rev = String(x).split('').reverse().join('');
  const result = parseInt(rev);

  if (result > max) return 0;
  return isNegative ? -result : result;
};
// @lc code=end

// @after-stub-for-debug-begin
module.exports = reverse;
// @after-stub-for-debug-end
